<?php

/**
 * 微博秀
 *
 * @author 狐狸<foxis@qq.com>
 * @package jishigou.net
 */



if(!defined('IN_JISHIGOU'))
{
    exit('invalid request');
}

class ModuleObject extends MasterObject
{

	function ModuleObject($config)
	{
		$this->MasterObject($config);

		Load::logic('topic');
		$this->TopicLogic = new TopicLogic($this);

		$this->CacheConfig = ConfigHandler::get('cache');

		$this->shareConfig = ConfigHandler::get('share');



		$this->Execute();
	}


	

	function Execute()
	{
		ob_start();
		switch($this->Code)
		{

			case 'show':
				$this->Show();
				break;

			default:
				$this->Main();
				break;
		}
		$body=ob_get_clean();

		$this->ShowBody($body);
	}


		function Main()
	{

		$uid = $this->Get['uid'] ? $this->Get['uid'] : MEMBER_ID;
		
		
		if($uid)
		{
						$members = $this->TopicLogic->GetMember($uid,"`uid`,`ucuid`,`username`,`nickname`,`face_url`,`face`,`topic_count`,`fans_count`,`validate`,`province`,`city`");
		    if(false===strpos($members['face'],':/'.'/'))
		    {
		        $members['face'] = $this->Config['site_url'] . "/" . $members['face'];
		    }

								$this->DatabaseHandler->SetTable(TABLE_PREFIX.'topic_show');
				$showlist=$this->DatabaseHandler->Select('',"uid='{$uid}'");
				$style = @unserialize($showlist['stylevalue']);

				$show_user 		= $style['show_user']   ? $style['show_user'] 	: '1';
				$userlimit 		= $show_user * 4;

								$width 			= $style['width'] 			? $style['width'] 			: '300';
				$height 		= $style['height'] 			? $style['height'] 			: '500';
				$bg_color 		= $style['bg_color'] 	 	? $style['bg_color'] 		: '#FFFFFF';
				$text_color		= $style['text_color'] 		? $style['text_color'] 	: '#666666';
				$link_color 	= $style['link_color'] 		? $style['link_color'] 	: '#0082CB';
				$title_color 	= $style['title_color'] 	? $style['title_color'] : '#D6F3F7';


								$isfans 		= $style['isfans'];
				$istitle 		= $style['istitle'];
				$istopic 		= $style['istopic'] ;
				
				
								$sql = "select `uid` as id from `".TABLE_PREFIX."buddys` where `buddyid`='{$uid}' order by `id` desc";
				$query = $this->DatabaseHandler->Query($sql);
				$uids = array();
				while ($row = $query->GetRow())
				{
					$uids[$row['id']] = $row['id'];
				}

				$user_list = $this->TopicLogic->GetMember("where `uid` in('".implode("','",$uids)."') limit {$userlimit}","`uid`,`ucuid`,`username`,`nickname`,`face_url`,`face`,`topic_count`,`fans_count`,`validate`,`province`,`city`");

								$where = "where `uid` = '{$uid}' and `type` != 'reply' order by `dateline` desc limit 0,20 ";
				
				$topic_list = $this->TopicLogic->Get($where);
			}
				include  $this->TemplateHandler->Template('iframe_show');

		}


	function Show()
	{
		$this->Member = $this->_member();

		$act_list = array('share'=>'分享到微博',);
		
		$act_list['show'] = array('name'=>'微博秀','link_mod'=>'show','link_code'=>'show',);    

        if($this->Config['qqwb_enable'] && qqwb_init($this->Config))
        {
            $act_list['qqwb'] = 'QQ微博';
        }                
        $act_list['imjiqiren'] = 'QQ机器人';        
		if ($this->Config['sina_enable'] && sina_weibo_init($this->Config))
		{
			$act_list['sina'] = '新浪微博';
		}
        if('qqrobot'==$this->Code && !isset($act_list['qqrobot']) && isset($act_list['imjiqiren']))
        {
            $this->Code = 'imjiqiren';
        }
        $act_list['medal'] = array('name'=>'勋章','link_mod'=>'other','link_code'=>'medal',);  
        $act_list['sms'] = '短信';    
		$act = isset($act_list[$this->Code]) ? $this->Code : 'show';


		extract($this->Get);
		extract($this->Post);

		$uid = $this->Post['uid'] ? $this->Post['uid'] : MEMBER_ID;

				$this->DatabaseHandler->SetTable(TABLE_PREFIX.'topic_show');
		$showlist=$this->DatabaseHandler->Select('',"uid='{$uid}'");
		$style = @unserialize($showlist['stylevalue']);

		$width 				= $style['width'] 			? $style['width'] 			: '300';
		$height 			= $style['height'] 			? $style['height'] 			: '500';
		$bg_color 		= $style['bg_color'] 	 	? $style['bg_color'] 		: '#FFFFFF';
		$text_color		= $style['text_color'] 	? $style['text_color'] 	: '#666666';
		$link_color 	= $style['link_color'] 	? $style['link_color'] 	: '#0082CB';
		$title_color 	= $style['title_color'] ? $style['title_color'] : '#D6F3F7';
		$show_user 		= $style['show_user']   ? $style['show_user'] 	: '1';

				$isfans 		= $style['isfans'];
		$istitle 		= $style['istitle'];
		$istopic 		= $style['istopic'];


    $this->Title = '微博秀';
		include  $this->TemplateHandler->Template('topic_show');
	}

	function _member()
	{
		if (MEMBER_ID < 1) {
			$this->Messager(null,$this->Config['site_url'] . "/index.php?mod=login");
		}

		$member = $this->TopicLogic->GetMember(MEMBER_ID);

		return $member;
	}

}
?>
